<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This element suppose to represent something similar to:
 * <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */
class Activitystream_ObjectType implements Atom_ChildElement {

    private $objectType;
    
    const TYPE_PERSON = 'http://activitystrea.ms/schema/1.0/person';
    const TYPE_NOTE = 'http://activitystrea.ms/schema/1.0/note';
    const TYPE_COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
    const TYPE_GROUP = 'http://activitystrea.ms/schema/1.0/group';
    const TYPE_PHOTO = 'http://activitystrea.ms/schema/1.0/photo';
    
    const ELEMENT_OBJECTTYPE = "object-type";
    
    public function __construct($objectType) {
        $this->setObjectType($objectType);
    }
    
    private function setObjectType($objectType) {
        if(empty($objectType)) {
            throw new Exception("ObjecType cannot be set empty.");
        }
        $this->objectType = $objectType;
    }
    
    public function getObjectType() {
        return $this->objectType;
    }
    
    /**
     * This should return elemnt representing something similar to:
     * <activity:object-type>http://activitystrea.ms/schema/1.0/person</activity:object-type>
     * 
     * @return DOMElement
     */
    public function asDomElement(DOMDocument $dom) {
        return $dom->createElement(ActivityStream::AS_NS_PREFIX. ':' . self::ELEMENT_OBJECTTYPE, $this->objectType);
    }
    
    /**
     * @param DOMElement $elm
     * @return Activitystream_ObjectType 
     */
    public static function buildFromDOMElement(DOMElement $elm) {
        return new Activitystream_ObjectType($elm->nodeValue);
    }
}